<?php

namespace Proj\ResManBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Project
 *
 * @ORM\Table(name="project")
 * @ORM\Entity(repositoryClass="Proj\ResManBundle\Entity\Repository\ProjectRepository")
 */
class Project
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=100)
     */
    private $name;

    /**
     * @var string
     *
     * @ORM\Column(name="description", type="string", length=255)
     */
    private $description;

    /**
     * @var Date
     *
     * @ORM\Column(name="start_date", type="date")
     */
    private $startDate;

    /**
     * @var Date
     *
     * @ORM\Column(name="end_date", type="date")
     */
    private $endDate;

    /**
     * @var string
     *
     * @ORM\Column(name="state", type="string", length=255)
     */
    private $state;

    /**
     * @var Department
     *
     * @ORM\ManyToOne(targetEntity="Department", inversedBy="projects")
     * @ORM\JoinColumn(name="depatment_id", referencedColumnName="id")
     */
    private $department;
	
    //tipuri de proiect: 
    //Cercetare - 0
    //Administrativ - 1
    /**
     * @var string
     *
     * @ORM\Column(name="type", type="string", length=255)
     */
    private $type;
    
    /**
     *
     * @var \DateTime
     * 
     * @ORM\Column(name="creation_date", type="datetime", nullable=false) 
     */
    private $creationDate;
    
    /**
     *
     * @var \Doctrine\Common\Collections\ArrayCollection
     * 
     * @ORM\ManyToMany(targetEntity="Person", inversedBy="projects")
     * @ORM\JoinTable(
     *      name="project_people",
     *      joinColumns={@ORM\JoinColumn(name="project_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="person_id", referencedColumnName="id")}
     * )
     */
    private $people;
    
    /**
     *
     * @var \Doctrine\Common\Collections\ArrayCollection
     * 
     * @ORM\ManyToMany(targetEntity="ResearchPhase")
     * @ORM\JoinTable(
     *      name="project_phase",
     *      joinColumns={@ORM\JoinColumn(name="project_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="phase_id", referencedColumnName="id", unique=true)}
     * )
     */
    private $phaseList;
    
    /**
     *
     * @var \Doctrine\Common\Collections\ArrayCollection
     * 
     * @ORM\OneToMany(targetEntity="Activity", mappedBy="project", cascade={"remove"})
     */
    private $activities;

    /**
     * @var boolean
     *
     * @ORM\Column(name="approved", type="boolean")
     */
    private $approved;
    
    
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->people = new \Doctrine\Common\Collections\ArrayCollection();
        $this->phaseList = new \Doctrine\Common\Collections\ArrayCollection();
        $this->activities = new \Doctrine\Common\Collections\ArrayCollection();
    }
    
    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     * @return Project
     */
    public function setName($name)
    {
        $this->name = $name;
    
        return $this;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set description
     *
     * @param string $description
     * @return Project
     */
    public function setDescription($description)
    {
        $this->description = $description;
    
        return $this;
    }

    /**
     * Get description
     *
     * @return string 
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Set startDate
     *
     * @param \DateTime $startDate
     * @return Project
     */
    public function setStartDate($startDate)
    {
        $this->startDate = $startDate;
        
        return $this;
    }

    /**
     * Get startDate
     *
     * @return \DateTime 
     */
    public function getStartDate()
    {
        return $this->startDate;
    }

    /**
     * Set endDate
     *
     * @param \DateTime $endDate
     * @return Project
     */
    public function setEndDate($endDate)
    {
        $this->endDate = $endDate;
    
        return $this;
    }

    /**
     * Get endDate
     *
     * @return \DateTime 
     */
    public function getEndDate()
    {
        return $this->endDate;
    }

    /**
     * Set state
     *
     * @param string $state
     * @return Project
     */
    public function setState($state)
    {
        $this->state = $state;
    
        return $this;
    }

    /**
     * Get state
     *
     * @return string 
     */
    public function getState()
    {
        return $this->state;
    }

    /**
     * Set type
     *
     * @param string $type
     * @return Project
     */
    public function setType($type)
    {
        $this->type = $type;
    
        return $this;
    }

    /**
     * Get type
     *
     * @return string 
     */
    public function getType()
    {
        return $this->type;
    }

    /**
     * Set creationDate
     *
     * @param \DateTime $creationDate
     * @return Project
     */
    public function setCreationDate($creationDate)
    {
       $this->creationDate = $creationDate;
        
       return $this;
    }
   
    /**
     * Get creationDate
     *
     * @return \DateTime 
     */
    public function getCreationDate()
    {
        return $this->creationDate;
    }

    /**
     * Set department
     *
     * @param \Proj\ResManBundle\Entity\Department $department
     * @return Project
     */
    public function setDepartment(\Proj\ResManBundle\Entity\Department $department = null)
    {
        $this->department = $department;
    
        return $this;
    }

    /**
     * Get department
     *
     * @return \Proj\ResManBundle\Entity\Department 
     */
    public function getDepartment()
    {
        return $this->department;
    }

    /**
     * Add people
     *
     * @param \Proj\ResManBundle\Entity\Person $people
     * @return Project
     */
    public function addPeople(\Proj\ResManBundle\Entity\Person $people)
    {
        $this->people[] = $people;
    
        return $this;
    }

    /**
     * Remove people
     *
     * @param \Proj\ResManBundle\Entity\Person $people
     */
    public function removePeople(\Proj\ResManBundle\Entity\Person $people)
    {
        $this->people->removeElement($people);
    }

    /**
     * Get people
     *
     * @return \Doctrine\Common\Collections\ArrayCollection 
     */
    public function getPeople()
    {
        return $this->people;
    }

    /**
     * Add phaseList
     *
     * @param \Proj\ResManBundle\Entity\ResearchPhase $phaseList
     * @return Project
     */
    public function addPhaseList(\Proj\ResManBundle\Entity\ResearchPhase $phaseList)
    {
        $this->phaseList[] = $phaseList;
    
        return $this;
    }

    /**
     * Remove phaseList
     *
     * @param \Proj\ResManBundle\Entity\ResearchPhase $phaseList
     */
    public function removePhaseList(\Proj\ResManBundle\Entity\ResearchPhase $phaseList)
    {
        $this->phaseList->removeElement($phaseList);
    }

    /**
     * Get phaseList
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getPhaseList()
    {
        return $this->phaseList;
    }

    /**
     * Add activities
     *
     * @param \Proj\ResManBundle\Entity\Activity $activities
     * @return Project
     */
    public function addActivitie(\Proj\ResManBundle\Entity\Activity $activities)
    {
        $this->activities[] = $activities;
    
        return $this;
    }

    /**
     * Remove activities
     *
     * @param \Proj\ResManBundle\Entity\Activity $activities
     */
    public function removeActivitie(\Proj\ResManBundle\Entity\Activity $activities)
    {
        $this->activities->removeElement($activities);
    }

    /**
     * Get activities
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getActivities()
    {
        return $this->activities;
    }
    
    public static function loadValidatorMetadata(ClassMetadata $metadata)
    {
        $metadata->addPropertyConstraint('name', new NotBlank(array(
            'message' => 'You must enter a project name.'
        )));
        
        $metadata->addPropertyConstraint('description', new NotBlank(array(
            'message' => 'You must enter a description.'
        )));
        
        $metadata->addPropertyConstraint('startDate', new Assert\Date(array(
            'message' => 'You must pick a department.'
        )));
        
        $metadata->addPropertyConstraint('endDate', new Assert\Date(array(
            'message' => 'You must pick a department.'
        )));
    }

    /**
     * Set approved
     *
     * @param boolean $approved
     * @return Project
     */
    public function setApproved($approved)
    {
        $this->approved = $approved;

        return $this;
    }

    /**
     * Get approved
     *
     * @return boolean 
     */
    public function getApproved()
    {
        return $this->approved;
    }

    /**
     * Add people
     *
     * @param \Proj\ResManBundle\Entity\Person $people
     * @return Project
     */
    public function addPerson(\Proj\ResManBundle\Entity\Person $people)
    {
        $this->people[] = $people;

        return $this;
    }

    /**
     * Remove people
     *
     * @param \Proj\ResManBundle\Entity\Person $people
     */
    public function removePerson(\Proj\ResManBundle\Entity\Person $people)
    {
        $this->people->removeElement($people);
    }

    /**
     * Add activities
     *
     * @param \Proj\ResManBundle\Entity\Activity $activities
     * @return Project
     */
    public function addActivity(\Proj\ResManBundle\Entity\Activity $activities)
    {
        $this->activities[] = $activities;

        return $this;
    }

    /**
     * Remove activities
     *
     * @param \Proj\ResManBundle\Entity\Activity $activities
     */
    public function removeActivity(\Proj\ResManBundle\Entity\Activity $activities)
    {
        $this->activities->removeElement($activities);
    }
}
